<?php $this->load->view('head'); ?>
<script type="text/javascript" src="<?php echo get_static_url();?>admin/js/tag.js"></script>
<script type="text/javascript">
    $(function() {
        $('#body1').xheditor({upImgUrl: '!/static/xheditor/xheditor_plugins/multiupload/multiupload.html', upFlashUrl: '/static/xheditor/xheditor_plugins/multiupload/multiupload.html', upMediaUrl: '/static/xheditor/xheditor_plugins/multiupload/multiupload.html'});
    });
    function addphoto() {
        var inputs = $("#content_photo input[name='photos[]']");
        var flag = inputs.length + 1;
        $("#content_photo").append('<div class="add_item"  id="photo' + flag + '"><label>图片' + flag + '：</label><div>&nbsp<input type="text" name="photos[]" class="txt width400" id="phototext' + flag + '" >&nbsp;<span>alt:</span>&nbsp;<input type="text" name="photoalts[]" class="txt width200" id="photoalt' + flag + '" >&nbsp;<a href="javascript:showupwindow(\'phototext' + flag + '\')" style="float:none">上传</a>&nbsp;<a href="javascript:delphoto(' + flag + ')"  style="float:none">删除</a><br/><br/><label>描述：</label><textarea name="phototext[]" style="width:640px;height:70px;"></textarea></div></div>');
        //showupwindow('phototext' + flag);
    }

    function delphoto(flag) {
        $("#photo" + flag).remove();
    }

    function showupwindow(id) {
        $('#h_pic').val(id);
        $('body').append('<div style="width: 349px; height: 220px; margin-left: -175px; margin-top: -110px; top: 355px;" class="xheModal" id="div_up"><div class="xheModalTitle"><span title="关闭 (Esc)" class="xheModalClose" onclick="close_up()"></span>上传文件</div><div class="xheModalContent" style="height: 191px;"><iframe frameborder="0" style="width: 100%; height: 100%;" src="/static/xheditor/xheditor_plugins/multiupload/multiupload.html?watermark=0"></iframe></div></div>');
        $('#div_up').css('top', $(document).scrollTop() + (window.screen.availHeight / 2 - 80));
    }
    function close_up() {
        $('#div_up').remove();
        $('#content_photo p').last().remove();
    }
    var mcontent;
    $(function(){
        mcontent = $("#separteImg").html();
        if (mcontent != ''){
            var div = $("<div>");
            $(div).html(mcontent);
            var imgs = $(div).find("img");
            var texts = $(div).find("p");
            for (var i = 0; i < imgs.length; i++){
                var flag = i + 1;
                var textarea = '';
                var checkboxs;
                var outHTML = texts[i].outerHTML;
                var patt1 = new RegExp("center");
                if (patt1.test(outHTML)){
                    checkboxs = '<input type="checkbox" name="photostatus" checked/>';
                }else{
                    checkboxs = '<input type="checkbox" name="photostatus"/>';
                }
                if (texts[i])textarea = texts[i].innerHTML;
//                $("#content_photo").append('<p id="photo' + flag + '">图片' + flag + ':&nbsp;<input type="text" name="photos" style="width:400px;" id="phototext' + flag + '" value="' + imgs[i].src + '" >&nbsp;alt:&nbsp;<input type="text" name="photoalts" style="width:200px;" id="photoalt' + flag + '" value="' + imgs[i].alt + '" >&nbsp;<a href="javascript:modifyphoto(' + flag + ')" >修改</a>&nbsp;<a href="javascript:delphoto(' + flag + ')" >删除</a><br/>说明:&nbsp;&nbsp;&nbsp;<textarea name="phototext" style="width:640px;height:70px;">' + textarea + '</textarea>' + checkboxs + '</p>');
                $("#content_photo").append('<div class="add_item" id="photo' + flag + '"><label>图片' + flag + '：</label><div >&nbsp<input type="text" name="photos[]" class="txt width400" id="phototext' + flag + '" value="' + imgs[i].src + '">&nbsp;<span>alt:</span>&nbsp;<input type="text" name="photoalts[]" class="txt width200" id="photoalt' + flag + '" value="' + imgs[i].alt + '">&nbsp;<a href="javascript:showupwindow(\'phototext' + flag + '\')" style="float:none">上传</a>&nbsp;<a href="javascript:delphoto(' + flag + ')"  style="float:none">删除</a><br/><br/><label>描述：</label><textarea name="phototext[]" style="width:640px;height:70px;">' + textarea + '</textarea></div></div>');
            
            }
        }
    })
</script>
<div class="main clear">
    <form name="article_form" id="article_form" method="post" action="index.php?d=admin&c=photo&m=cmd_save">
        <div class="add_item" style="margin-top: 10px;">
            <label>文章标题：</label>
            <input type="text" value="<?php if(isset($data['title'])){echo $data['title'];}?>" id="title" name="title" class="txt width500">
        </div>
        <div class="add_item">
            <label>短标题：</label>
            <input type="text" value="<?php if(isset($data['shorttitle'])){echo $data['shorttitle'];}?>" name="shorttitle" class="txt width500">
        </div>
        <div class="add_item">
            <label>关键词：</label>
            <input type="text" value="<?php if(isset($data['keywords'])){echo $data['keywords'];}?>" name="keywords" class="txt width500">
        </div>
        <div class="add_item">
            <label>自定义属性：</label>
            <div class="add_cbox" style="width: 600px;">
                <input type="checkbox" value="c" name="flag[]" class="checkbox" <?php if(isset($data['flag']) && strpos($data['flag'],'c') !== false){?> checked="checked" <?php }?>>
                <span>推荐</span>
                <input type="checkbox" value="f" name="flag[]" class="checkbox" <?php if(isset($data['flag']) && strpos($data['flag'],'f') !== false){?> checked="checked" <?php }?>>
                <span>幻灯</span>
                <input type="checkbox" value="a" name="flag[]" class="checkbox" <?php if(isset($data['flag']) && strpos($data['flag'],'a') !== false){?> checked="checked" <?php }?>>
                <span>首页推荐</span>
            </div>
        </div>
        <div class="add_item">
            <label>游戏名称：</label>
            <input type="text" value="<?php if(isset($data['gamename'])){echo $data['gamename'];}?>" name="gamename" class="txt width500">
        </div>
        <div class="add_item">
            <label>标签：</label>
            <input type="text" value="<?php if(isset($data['tag1'])){echo $data['tag1'];}?>" name="tag" id="tag" class="txt width500">
            <span id="ktjbq">多个标签，使用逗号隔开</span>
        </div>
        <div class="add_item">
            <label>常用标签：</label>
            <div  id="tags" class="tags"><div><a href="javascript:moreTag()" id="moretag">点击查看更多</a></div><br/><?php if(isset($tags)){echo $tags;}?></div>
            
            <style type="text/css">
                .tags{width: 1000px;height: 110px;float: left;overflow: hidden}
                .tags_more{width: 1000px;float: left;}
            </style>
        </div>
<!--        <div class="add_item">
            <label>列表页缩略图：</label>
            <input type="hidden" value="" id="h_pic">
            <input type="text" value="<?php if(isset($data['listpic'])){echo $data['listpic'];}?>" id="listpic" name="listpic" class="txt width500">
            <a onclick="showupwindow('listpic')" href="javascript:;">上传</a>
        </div>-->
        <div class="add_item">
            <label>缩略图：</label>
            <input type="hidden" value="" id="h_pic">
            <input type="text" value="<?php if(isset($data['litpic'])){echo $data['litpic'];}?>" id="litpic" name="litpic" class="txt width500">
            <a onclick="showupwindow('litpic')" href="javascript:;">上传</a>
            <span style="color: silver;">列表页logo图，大小170*130</span>
        </div>
        <div class="add_item">
            <label>内容：</label>
            <a href="javascript:addphoto()">添加图片</a><br/>
            <div id='content_photo' style="padding-top:10px;"></div>
        </div>
        
        <div class="" style="float: left;line-height: 32px;margin-bottom: 10px; width: 100%;">
            <label style="float: left;font-size: 14px;font-weight: bold;text-align: right;width: 100px;">内容摘要：</label>
            <textarea style="width:640px;height:70px;background: none repeat scroll 0 0 #fff;border: 1px solid #c6c6c6;color: #666;float: left;margin-right: 10px;padding-left: 10px;"  name="miaoashu"><?php if(isset($data['description'])){echo $data['description'];}?></textarea>
           
        </div>
        <div style="display: none">
            <textarea style="width:640px;height:70px;"  name="" id="body1"></textarea>
        </div>
        <div class="add_item">
            <label>文章来源：</label>
            <input type="text" value="<?php if(isset($data['source'])){echo $data['source'];}?>" name="source" class="txt width300">
        </div>

        <div class="add_item">
            <label>文章作者：</label>
            <input type="text" value="<?php if(isset($data['writer'])){echo $data['writer'];}?>" name="writer" class="txt width300">
        </div>
        <div class="add_item">
            <label>发布时间：</label>
            <input type="text" onclick="SelectDate(this, 'yyyy-MM-dd hh:mm:00')"  value="<?php if (isset($data['pubdate'])) {echo $data['pubdate'];} ?>" name="pubdate" class="txt width300">
        </div>
        <div style="display:none" id='separteImg'><?php if(isset($data['body'])){echo $data['body'];}?></div>
        
        <div class="btn_box">
            <input type="hidden" id="content" name="body" value=""/>
            <input type="hidden" value="<?php if(isset($id)){echo $id;}?>"  name="id" />
            <input type="hidden" value="<?php if(isset($data['typeid'])){echo $data['typeid'];}?>"  name="tid" />
            <input type="button" onclick="submit()" value="保存" />
            <input type="button" onclick="fanhui()" value="返回" />
        </div>
        <script type="text/javascript">
            function submit(){
                if ($('#title').val() == '') {
                    alert('请输入标题!');
                    document.getElementById('title').focus();
                    return false;
                }
                $("#article_form").submit();
            }
        </script>
    </form>
</div>

<?php $this->load->view('foot'); ?>